import java.util.ArrayList;


public class Main {
	public static void main(String[] args) {
		
		
		if(args.length != 1) {
			System.out.println("Wrong number of arguments!");
			System.out.println("Correct usage: java -jar Homework3.jar NameOfPERTFile.pert");
			System.exit(0);
		} else {
			TaskReader reader = new TaskReader();
			TaskUtil util = new TaskUtil();
			ArrayList<Task> tasks = (ArrayList<Task>) reader.readChartFromFile(args[0]);
			
			Validator validator = new Validator();
			boolean isValid = validator.validateChart(tasks);
			
			if(!isValid) {
				System.out.println("Validation errors.");
				System.exit(0);
			}
			
			Task startTask = util.findStartNode(tasks);
			Task endTask = util.findEndNode(tasks);
			endTask.calculateEarlyTimes();
			endTask.setLateFinish(endTask.getEarlyFinish());
			startTask.calculateLateTimes();
			
			for(Task task : tasks) {
				task.calculateSlack();
			}
			
			util.printCriticalPath(startTask);
		}
	}
}
